import os
from typing import Optional


class Config:
    """统一管理所有环境变量"""
    
    @staticmethod
    def get_str(key: str, default: Optional[str] = None) -> str:
        value = os.getenv(key, default)
        if value is None:
            raise ValueError(f"Missing required env var: {key}")
        return value
    
    @staticmethod
    def get_bool(key: str, default: bool = False) -> bool:
        val = os.getenv(key, "").lower()
        if val in ("true", "1", "t"):
            return True
        elif val in ("false", "0", "f"):
            return False
        return default
    
    @staticmethod
    def get_int(key: str, default: int = 0) -> int:
        try:
            return int(os.getenv(key, str(default)))
        except ValueError:
            return default
        